package com.newgoldcurrency.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.newgoldcurrency.App;
import com.newgoldcurrency.bean.IncomeBean;
import com.newgoldcurrency.databinding.ItemIncomeBinding;

import java.util.List;

public class IncomeAdapter extends ArrayAdapter<IncomeBean> {
    private final Activity context;
    public IncomeAdapter(@NonNull Activity context, @NonNull List<IncomeBean> objects) {
        super(context, 0, objects);
        this.context=context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        @SuppressLint("ViewHolder") @NonNull ItemIncomeBinding binding = ItemIncomeBinding.inflate(context.getLayoutInflater());
        IncomeBean bean = getItem(position);
        binding.itemIncomeName.setText(bean.invitationCode);
        binding.itemIncomeAdd.setText("+"+bean.goldCoins);
        binding.itemIncomeTime.setText(bean.time);
        if (!bean.user_id.equals(App.userBean.id)){
            binding.itemIncomeName.setText(bean.invitationCode);
        }else{
            if (bean.surprise){
                binding.itemIncomeName.setText("Surprise:");
            }else {
                binding.itemIncomeName.setText("Earning:");
            }
        }
        return binding.getRoot();
    }
}
